<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    public function run() {
        // Cela permet d'avoir le fichier de configuration disponible depuis n'importe ou dans l'application.
        Zend_Registry::set('config', new Zend_Config($this->getOptions()));
        parent::run();
    }

    /**
     *  Initialise les namespaces 
     *  Ajouter les nouveaux modules ici pour le chargement automatique des classes
     */
    protected function _initDefaultNamespace() {
        $this->bootstrap('frontcontroller');
        $front = $this->getResource('frontcontroller');
        $defaultModule = $front->getDefaultModule();

        // default module
        new Zend_Application_Module_Autoloader(array('namespace' => '',
                    'basePath' => APPLICATION_PATH . '/modules/' . $defaultModule,
                ));

        // admin 
        new Zend_Application_Module_Autoloader(array('namespace' => 'Admin',
                    'basePath' => APPLICATION_PATH . '/modules/admin',
                ));
    }

    /**
     * Initialise la gestion des mails 
     */
    protected function _initMails() {
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'mail');
        $mailConfig = $config->toArray();

        Zend_Registry::set('Mail_Config', $mailConfig['mail']['config']);
    }

    protected function _initDoctype() {
        $this->bootstrap('view');
        $view = $this->getResource('view');
//        $view->doctype('XHTML1_STRICT');
        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8');
        // ajouts des fichiers css et javascript ici
        $view->headLink()
//                ->appendStylesheet('/appliweb/public/menu/css/style.css')
                ->appendStylesheet('/appliweb/public/jqueryui/css/custom-theme/jquery-ui-1.8.21.custom.css')
                ->appendStylesheet('/appliweb/public/css/style.css')
                ->appendStylesheet('/appliweb/public/css/styleIE.css', 'screen', 'IE')
                ->appendStylesheet('/appliweb/public/fancybox/source/jquery.fancybox.css')
                ->appendStylesheet('/appliweb/public/bubble/css/style.css');
        $view->headScript()
                ->appendFile('/appliweb/public/fancybox/lib/jquery-1.7.2.min.js')
                ->appendFile('/appliweb/public/fancybox/lib/jquery.mousewheel-3.0.6.pack.js')
                ->appendFile('/appliweb/public/fancybox/source/jquery.fancybox.pack.js')
                ->appendFile('/appliweb/public/fancybox/source/jquery.fancybox.js')
                ->appendFile('/appliweb/public/bubble/jquery.easing.1.3.js')
                ->appendFile('/appliweb/public/jqueryui/js/jquery-ui-1.8.21.custom.min.js')
                ->appendFile('/appliweb/public/js/appliweb.js')
                ->appendFile('/appliweb/public/ckeditor/ckeditor_basic.js');

        // $view->headScript()->appendFile($view->baseUrl("path/to/script.js"));
    }

    /**
     * Initialise la session
     * @return \Zend_Session_Namespace 
     */
    protected function _initSession() {
        // On initialise la session
        $session = new Zend_Session_Namespace('appliweb', true);
        Zend_Registry::set('session', $session);
        return $session;
    }

    /*     * *
     * Initialise les traductions
     */

    protected function _initTranslate() {
        $translate = new Zend_Translate('array', APPLICATION_PATH . '/languages/fr_FR.php', 'fr');
        $translate->addTranslation(APPLICATION_PATH . '/languages/en_US.php', 'en');
        //changer la locale
        $translate->setLocale('fr');
        Zend_Registry::set('Zend_Translate', $translate);
        return $translate;
    }

    /*     * *
     * Initialise la navigation
     */

    protected function _initNavigation() {
        $view = $this->bootstrap('layout')->getResource('layout')->getView();
        $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
        $view->navigation(new Zend_Navigation($config));
    }

}

